<div class="tmd-doc">
<p></p>
<h1 class="tmd-header-1">
How to create slices?
</h1>
<p></p>
<div class="tmd-usual">
Assume the type of a new created slice is <code class="tmd-code-span">S</code> and <code class="tmd-code-span">s0</code> is the zero value literal of <code class="tmd-code-span">S</code>.
</div>
<p></p>
<h2 class="tmd-header-2">
Way 1 (use composite literals)
</h2>
<p></p>
<pre class="tmd-code">
<code class="language-Go">	var aSlice = S{} // both length and capacity are zero
	// or
	var aSlice = S{Len - 1: s0} // both length and capacity are Len (a constant)
</code></pre>
<p></p>
<div class="tmd-usual">
The capacity of the result slice is not always aligned to a memory class size. <span class="tmd-italic">(Memory class sizes are mentioned in </span><a href="https://go101.org/optimizations/0.3-memory-allocations.html"><span class="tmd-italic">Go Optimizations 101</span></a><span class="tmd-italic">.)</span>
</div>
<p></p>
<p></p>
<h2 class="tmd-header-2">
Way 2 (use the built-in <code class="tmd-code-span">make</code> function):
</h2>
<p></p>
<pre class="tmd-code">
<code class="language-Go">	var aSlice = make(S, initialLength, capacity)
	// or
	var aSlice = make(S, initialLength) // capacity == initialLength
</code></pre>
<p></p>
<div class="tmd-usual">
The capacity of the result slice is not always aligned to a memory class size.
</div>
<p></p>
<h2 class="tmd-header-2">
Way 3 (use the built-in <code class="tmd-code-span">append</code> + <code class="tmd-code-span">make</code> functions):
</h2>
<p></p>
<pre class="tmd-code">
<code class="language-Go">	var aSlice = append(S{}, make(S, initialLength)...)
	// or
	var aSlice = append(S(nil), make(S, initialLength)...)
	// or
	var aSlice = append(S{}, make(S, initialLength, capacity)...)
	// or
	var aSlice = append(S(nil), make(S, initialLength, capacity)...)
</code></pre>
<p></p>
<div class="tmd-usual">
With the official toolchain, the capacity of the result slice is aligned to a memory class size.
</div>
<p></p>
</div>
